<template>
  <div class="photoinfo">
    <!-- header -->
    <van-panel
      class="my-panel"
      :title="imageInfo.title"
      :status="'阅读' + imageInfo.click + '次'"
    >
      <div class="content">
        {{ imageInfo.content }}
      </div>
    </van-panel>
    <div class="imgs-box">
      <img
        v-for="(item, index) in thumImages"
        :key="item.id"
        v-lazy="item.src"
        @click="showImage(index)"
      />
    </div>
    <!-- 评论组件 -->
    <Comment :id="id"></Comment>
  </div>
</template>
<script>
import { ImagePreview } from 'vant';
import Comment from '@/components/Comment';
export default {
  components: {
    Comment,
  },
  props: ['id'],
  data() {
    return {
      imageInfo: {},
      thumImages: [],
    };
  },
  created() {
    this.getImageInfo();
    this.getThumImages();
  },
  methods: {
    async getImageInfo() {
      const res = await this.$http.getImageInfo(this.id);
      this.imageInfo = res.data.message;
    },
    async getThumImages() {
      const res = await this.$http.getThumImages(this.id);
      this.thumImages = res.data.message;
    },
    showImage(startPosition) {
      // let images = [];
      // this.thumImages.forEach((item) => {
      //   if (item.src) images.push(item.src);
      // });
      let images = this.thumImages.map((item) => item.src);
      ImagePreview({
        images,
        startPosition,
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.photoinfo {
  padding: 0 10px;
  .van-cell__title {
    font-size: 16px;
    font-weight: 600;
  }
  .content {
    text-indent: 2em;
    font-size: 12px;
  }
  .my-panel {
    margin-bottom: 10px;
  }
  .imgs-box {
    display: flex;
    justify-content: space-between;
    margin: 10px 0;
    img {
      width: 100px;
      height: 100px;
    }
  }
}
</style>
